//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    paths: [],
    img_list:'',
    radioStr: '请选择投诉类型',
    textCounter: '',
    merchants_id:0,
    dialog: false,
    items: [{
      name: 'a',
      value: '商家客服态度差'
    },
    {
      name: 'b',
      value: '售卖假货',
    },
    {
      name: 'c',
      value: '成交不卖'
    },
    {
      name: 'd',
      value: '虚假发货'
    },
    {
      name: 'e',
      value: '超时发货'
    },
    {
      name: 'f',
      value: '运费到付'
    },
    {
      name: 'g',
      value: '涉嫌引导添加微信'
    },
    {
      name: 'h',
      value: '宣传与平台无关广告信息'
    },
  ],
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  // 投诉类型
  radioChange(e) {
    var that = this;
    var str = null;
    for (var value of that.data.items) {
      if (value.name === e.detail.value) {
        str = value.value;
      }
    }
    this.setData({
      radioStr: str,
      color: "#000"
    });
  },
 //文本框
 textareas(e) {
  var that = this;
  if (5 <= e.detail.cursor <= 300) {
    that.setData({
      textCounter: e.detail.value,
    })
  }
},  
   //添加图片
   addImg() {
    var that = this;
    var token = wx.getStorageSync('token');
    wx.chooseImage({
      count: 1,
      success(res) {
        const tempFilePaths = res.tempFilePaths;
        var img_list = that.data.img_list.concat(res.tempFilePaths);
      //  console.log("添加图片", img_list)
        that.setData({
          img_list: img_list
        })
        var paths = [];
      wx.uploadFile({
        url: 'https://www.zbq888.cn/api/v1/user/order/after/photo/insert',
        filePath: img_list,
        name: 'photo_file',
        header: {
          "token": token,
          "client": 1,
          "content-Type": "multipart/form-data",
        },
        formData: {
          "photo_file": img_list,
        },
        success(res) {
        //  console.log("上传图片", res)
          var data = JSON.parse(res.data)
          paths.push(data.photo_url)
          that.setData({
            paths: paths
          })
        }
      })
      }
    })
  },
   
  //举报
 submit(){
   var that = this;
  var token = wx.getStorageSync('token');
  wx.request({
    url: 'https://www.zbq888.cn/api/v1/user/report',
    method: 'post',
    data: {
      merchants_id:that.data.merchants_id,
      content: that.data.textCounter,
      images: that.data.paths,
      cate_string:that.data.radioStr,
    },
    header: {
      'content-type': 'application/x-www-form-urlencoded', //此处传参为query格式
      "client": 1,
      'token': token
    },
   success(res){
    //  console.log(res)
     if(that.data.radioStr=='请选择投诉类型'){
      wx.showToast({
        title: '请选择投诉类型',
        icon:'none'
      })
    } else if (that.data.textCounter.length<5){
      wx.showToast({
        title: '描述太短',
        icon:'none'
      })
    } else if (res.data.mark == 0) {
      wx.showToast({
        title: '举报成功',
        icon:'none'
      })
      setTimeout(() => {
        wx.navigateBack({
          url: '../sixin/sixin'
        })
      }, 1000)
    }
   }
  })
 },
   //关闭弹窗
   Dialogf() {
    this.setData({
      dialog: false
    })
  },
  //开启弹窗
  Dialogt() {
    this.setData({
      dialog: true
    })
  },
  
})